package nz.ac.massey.cs.se400_2013.ass3.plugin;

import javax.swing.JPanel;

import nz.ac.massey.cs.se400_2013.ass3.Address;
import nz.ac.massey.cs.se400_2013.ass3.EditorPlugin;

public class AddressEditor implements EditorPlugin{

	Object object;
	private AddressEditorUi editor = new AddressEditorUi();
	
	
	public JPanel getEditor() {
		return this.editor;
	}

	public void edit(Object obj) {
		this.object = obj;
		
		this.editor.setCity(((Address)obj).getCity());
		this.editor.setNo(((Address)obj).getNo());
		this.editor.setStreet(((Address)obj).getStreet());
	}

	public boolean canEditInstanceOf(Class type) {
		return Address.class ==  type;
	}

	public void saveObject() {
		((Address)this.object).setCity(this.editor.getCity());
		((Address)this.object).setStreet(this.editor.getStreet());
		((Address)this.object).setNo(this.editor.getNo());
	}

	@Override
	public void addChangeListener(ChangeListener listener) {
		this.editor.addChangeListener(listener);
	}

}
